package com.springcloud.common.web.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import java.time.LocalDateTime;

/**
 * <p>  </p>
 *
 * @author mori
 * @since 10/29/2019 11:15 AM
 */
@Slf4j
public abstract class DefaultMetaObjectHandler implements MetaObjectHandler {

    /**
     *  创建人
     * @return
     */
    public abstract String getCreatedBy();

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("created_by", getCreatedBy(), metaObject);
        this.setFieldValByName("created_date", LocalDateTime.now(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("modify_by", getCreatedBy(), metaObject);
        this.setFieldValByName("modify_date", LocalDateTime.now(), metaObject);
    }
}
